/*
	File:		CreditState.cpp
	Course:		SGD 1301
	Author:		Peter Nguyen
	Purpose:	CCreditState class handles the credit menu
*/

#include "CreditState.h"

#include "../SGD Wrappers/CSGD_DirectInput.h"
#include "../SGD Wrappers/CSGD_Direct3D.h"
#include "../SGD Wrappers/CSGD_TextureManager.h"

#include "Game.h"
#include "GameplayState.h"
#include "MainMenuState.h"
#include "BitmapFont.h"

#include <cassert>


////////////////////////////////////////////////////////////
// SINGLETON!
/*static*/ CCreditState* CCreditState::GetInstance( void )
{
	// Static local object
	static CCreditState s_Instance;

	return &s_Instance;
}


////////////////////////////////////////////////////////////
// CONSTRUCTOR
CCreditState::CCreditState(void)
{
	m_pDI		= nullptr;
	m_pTM		= nullptr;
	m_pFont		= nullptr;
}


////////////////////////////////////////////////////////////
// DESTRUCTOR
CCreditState::~CCreditState(void)
{
}


////////////////////////////////////////////////////////////
// Enter				- load resources
/*virtual*/ void CCreditState::Enter( void )
{
	// Store wrappers
	m_pDI		= CSGD_DirectInput::GetInstance();
	m_pTM		= CSGD_TextureManager::GetInstance();
	m_pFont		= CGame::GetInstance()->GetFont();
	scrollSpeedY = -(CGame::GetInstance()->GetHeight()/5.0f);
	startPositionY = (float)CGame::GetInstance()->GetHeight();
	endPositionY = 999999;//later set to a viable number
	exitTimer = 4.0f;
	isEndPositionSet = false;
}

////////////////////////////////////////////////////////////
// Exit					- unload resources
/*virtual*/ void CCreditState::Exit( void )
{
	// Reset the wrappers to null
	m_pDI		= nullptr;
	m_pTM		= nullptr;
	m_pFont		= nullptr;
}

////////////////////////////////////////////////////////////
// Input			- handle user input
/*virtual*/ bool CCreditState::Input( void )
{
	if( m_pDI->KeyPressed( DIK_ESCAPE ) )
		CGame::GetInstance()->PopState();
	if(exitTimer<=0)
		CGame::GetInstance()->PopState();

	return true;
}				

////////////////////////////////////////////////////////////
// Update			- update game entities
/*virtual*/ void CCreditState::Update( float fElapsedTime )
{
	if(startPositionY>endPositionY)
		startPositionY+=scrollSpeedY*fElapsedTime;
	else
		exitTimer-=fElapsedTime;
}

////////////////////////////////////////////////////////////
// Render			- render game entities
/*virtual*/ void CCreditState::Render( void )
{
	int space = 100;
	int start = (int)startPositionY;
	int current = start;
	
	m_pFont->Draw( _T("I Made A Game With Space Ship"),	100, current+=space, 1.0f, D3DCOLOR_ARGB( 255, 255, 255, 255 ) );
	m_pFont->Draw( _T("Programmer:"),					100, current+=space, 1.0f, D3DCOLOR_ARGB( 255, 255, 255, 255 ) );
	m_pFont->Draw( _T("  Peter Nguyen"),				100, current+=space, 1.0f, D3DCOLOR_ARGB( 255, 255, 255, 255 ) );
	m_pFont->Draw( _T("University:"),					100, current+=space, 1.0f, D3DCOLOR_ARGB( 255, 255, 255, 255 ) );
	m_pFont->Draw( _T("  Full Sail University"),		100, current+=space, 1.0f, D3DCOLOR_ARGB( 255, 255, 255, 255 ) );
	m_pFont->Draw( _T("Sounds:"),						100, current+=space, 1.0f, D3DCOLOR_ARGB( 255, 255, 255, 255 ) );
	m_pFont->Draw( _T("  CROW'SCLAW - Eclipced"),		100, current+=space, 1.0f, D3DCOLOR_ARGB( 255, 255, 255, 255 ) );
	m_pFont->Draw( _T("Twitter:"),						100, current+=space, 1.0f, D3DCOLOR_ARGB( 255, 255, 255, 255 ) );
	m_pFont->Draw( _T("  Peter.Nguyen.Dev"),			100, current+=space, 1.0f, D3DCOLOR_ARGB( 255, 255, 255, 255 ) );
	m_pFont->Draw( _T(""),								100, current+=space, 1.0f, D3DCOLOR_ARGB( 255, 255, 255, 255 ) );
	m_pFont->Draw( _T(""),								100, current+=space, 1.0f, D3DCOLOR_ARGB( 255, 255, 255, 255 ) );
	m_pFont->Draw( _T(""),								100, current+=space, 1.0f, D3DCOLOR_ARGB( 255, 255, 255, 255 ) );
	m_pFont->Draw( _T(""),								100, current+=space, 1.0f, D3DCOLOR_ARGB( 255, 255, 255, 255 ) );
	m_pFont->Draw( _T("Press Escape To Exit"),			100, current+=space, 1.0f, D3DCOLOR_ARGB( 255, 255, 255, 255 ) );

	if(!isEndPositionSet)
	{
		endPositionY = -(float)(current - start - CGame::GetInstance()->GetHeight()/2);
		isEndPositionSet = true;
	}
}
	